<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import="com.sun.jersey.api.client.config.ClientConfig" %>
    <%@ page import="com.sun.jersey.api.client.config.DefaultClientConfig" %> 
    <%@ page import="com.sun.jersey.api.client.*" %> 
    <%@ page import="javax.ws.rs.core.UriBuilder" %>
    <%@ page import="java.net.URI" %>
    <%@ page import="javax.ws.rs.core.UriBuilder" %>
    <%@ page import="java.util.*" %>
    <%@ page import="cs9322.assign3.model.*" %>
    <%@ page import="javax.ws.rs.core.MediaType" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Client for Barista</title>
<SCRIPT LANGUAGE="JavaScript">
document.write('<form><input type=button value="Refresh" onClick="history.go()"></form>')
</script>
<br><br><br>
<% response.addHeader("Refresh","5"); %>
<%
ClientConfig clientConfig = new DefaultClientConfig();
Client client = Client.create(clientConfig);
WebResource service = client.resource("http://localhost:8080/cs9322.assign3.coffee"); 
ClientResponse cr = service.path("starbucks").path("orders").accept(MediaType.TEXT_XML).get(ClientResponse.class);
List<Order> coffeeList = cr.getEntity(new GenericType<List<Order>>() {});
%>
</head>
<body>
<table>
	<% 
	for(int i=0; i<coffeeList.size();i++) {
		Order order = (Order)coffeeList.get(i);%>
		<% if(!order.getStatus().equalsIgnoreCase("released")) {%>
		<tr>
		<td>
		<a href="orderdetailbarista.jsp?id=<%=order.getId()%>">Coffee Order&nbsp<%=order.getId() %></a>
		</td>
		<td><form action="Prepare" method="post">
			<input type="hidden" name="id" value=<%=order.getId() %>>
			<input type="submit" value="Prepare">
		</form></td>
		<td><form action="paymentdetailforbarista.jsp" method="post">
			<input type="hidden" name="id" value=<%=order.getId() %>>
			<input type="submit" value="Check Payment">
		</form></td>
		<td><form action="Release" method="post">
			<input type="hidden" name="id" value=<%=order.getId() %>>
			<input type="submit" value="Release">
		</form>
		<td>&nbsp &nbsp &nbsp<%=order.getStatus() %>...</td>
		</td>
		<%} %>
		
	<%}%>
	</table>
	<br>
	<br>
	<br>
	<br>
	<table>
	<tr>
	<td>
	response status:
	</td>
	<td>
	<%=cr.getStatus() %>
	</td>
	</tr>
	<tr>
	<td>
	response headers:
	</td>
	<td>
	<%=cr.getHeaders() %>
	</td>
	</tr>
	<tr>
	<td>
	response data:
	</td>
	<td>
	<%=cr.getResponseDate() %>
	</td>
	</tr>
	</table>
</body>
</html>